package com.rogo.openapi.flickr
{
	import com.rogo.openapi.flickr.api.Test;
	import com.rogo.openapi.flickr.core.FlickrOAuth;
	
	/**
	 * FLICKR OPEN API
	 * 
	 * @author Rogo
	 */	
	public class Flickr
	{
		public function Flickr()
		{
			oauth = new FlickrOAuth();
			test = new Test();
		}
		
		//--------------------------------------------------------------------------
		//
		//  Variables
		//
		//--------------------------------------------------------------------------
		
		private static var instance:Flickr;
		
		private var oauth:FlickrOAuth;
		private var test:Test;
		
		public function get key():String
		{
			return oauth.key;
		}

		public function set key(value:String):void
		{
			oauth.key = value;
		}

		public function get secret():String
		{
			return oauth.secret;
		}

		public function set secret(value:String):void
		{
			oauth.secret = value;
		}

		public function get callback():String
		{
			return oauth.callback;
		}

		public function set callback(value:String):void
		{
			oauth.callback = value;
		}
		
		
		//--------------------------------------------------------------------------
		//
		//  OAUTH METHODS
		//
		//--------------------------------------------------------------------------
		
		public static function getInstance():Flickr
		{
			if (!instance)
				instance = new Flickr();
			
			return instance;
		}
		
		/**
		 * 登录
		 */		
		public function login():void
		{
			oauth.requestToken();
		}
		
		/**
		 * 认证
		 */		
		public function verify(verify:String):void
		{
			oauth.oauthKey.oauth_verifier = verify;
			oauth.accessToken();
		}
		
		//--------------------------------------------------------------------------
		//
		//  FLICKR.TEST METHODS
		//
		//--------------------------------------------------------------------------
		
		public function testLogin(resultHandler:Function = null, 
								  errorHandler:Function = null):void
		{
			test.login(resultHandler, errorHandler);
		}
		
	}
}